package com.pickgliss.utils
{
	import com.pickgliss.effect.EffectColorType;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.filters.GradientGlowFilter;
	import flash.geom.ColorTransform;

	/**
	 * 特效工具类
	 * @author Administrator
	 * 
	 */
	public class EffectUtils
	{
		/**
		 * 图片发光方法
		 * @param $target
		 * @param glow_intensity
		 * @param glow_blur
		 * @param glow_quality
		 * @param glow_color_name
		 * 
		 */
		public static function imageGlower($target:DisplayObject,glow_intensity:Number, glow_blur:Number, glow_quality:Number, glow_color_name:String):void 
		{
			var glow_distance:Number = 0;
			var glow_angleInDegrees:Number = 45;
			var glow_colors:Array;
			if(glow_color_name ==EffectColorType.YELLOW) {
				glow_colors = [0xFFA600,0xFFA600,0xFFA600,0xFFA600];
			}
			if (glow_color_name == EffectColorType.GOLD) {
				glow_colors = [0x660000, 0xFF6600, 0xFFAA00, 0xFFFFCC];
			}
			if (glow_color_name == EffectColorType.BLUE) {
				glow_colors = [0x003399, 0x003399, 0x0099FF, 0x99CCFF];
			}
			if (glow_color_name == EffectColorType.GREEN) {
				glow_colors = [0x006600, 0x339900, 0x99FF00, 0xFFFFCC];
			}
			if (glow_color_name == EffectColorType.OCEAN) {
				glow_colors = [0x003333, 0x336666, 0x99CCCC, 0xCCFFFF];
			}
			if (glow_color_name == EffectColorType.AQUA) {
				glow_colors = [0x003333, 0x006666, 0x00CCCC, 0x00FFFF];
			}
			if (glow_color_name == EffectColorType.ICE) {
				glow_colors = [0x003366, 0x336699, 0x6699CC, 0x99CCFF];
			}
			if (glow_color_name == EffectColorType.SPARK) {
				glow_colors = [0x000066, 0x006699, 0x33CCFF, 0xCCFFFF];
			}
			if (glow_color_name == EffectColorType.SILVER) {
				glow_colors = [0x333333, 0x666666, 0xBBBBBB, 0xFFFFFF];
			}
			if (glow_color_name == EffectColorType.NEON) {
				glow_colors = [0x3333CC, 0x6633CC, 0x9999FF, 0xCCCCFF];
			}
			var glow_alphas:Array = [0, 1, 1, 1];
			var glow_ratios:Array = [0, 63, 126, 255];
			var glow_blurX:Number = glow_blur;
			var glow_blurY:Number = glow_blur;
			var glow_strength:Number = glow_intensity;
			var glow_quality:Number = glow_quality;
			var glow_type:String = "outer";
			var glow_knockout:Boolean = false;
			var filter:GradientGlowFilter = new GradientGlowFilter(glow_distance, glow_angleInDegrees, glow_colors, glow_alphas, glow_ratios, glow_blurX, glow_blurY, glow_strength, glow_quality, glow_type, glow_knockout);
			var filterArray:Array = new Array();
			filterArray.push(filter);
			$target.filters = filterArray;
		}
		
		/**
		 * 改变颜色
		 * @param $target
		 * @param shine_intensity
		 * 
		 */
		public static function imageShiner($target:DisplayObject,shine_intensity:Number):void
		{
			var colorTrans:ColorTransform = new ColorTransform();
			var color:Number = shine_intensity;
			colorTrans.redOffset = color;
			colorTrans.redMultiplier = (color/100)+1;
			colorTrans.greenOffset = color;
			colorTrans.greenMultiplier = (color/100)+1;
			colorTrans.blueOffset = color;
			colorTrans.blueMultiplier = (color/100)+1;
			$target.transform.colorTransform = colorTrans;
		}
		
		/**
		 * MC转变IMG
		 * @param $target
		 * @param $color
		 * @return 
		 * 
		 */
		public static function creatMcToBitmap($target:DisplayObject,$color:uint):Bitmap
		{
			var bitmapData:BitmapData = new BitmapData($target.width,$target.height,true,$color);
			bitmapData.draw($target);
			var bitmap:Bitmap = new Bitmap(bitmapData);
			return bitmap;
		}
		
		/**
		 * 角度
		 * @param degree
		 * @return 
		 * 
		 */
		public static function toRadian(degree:Number):Number 
		{
			return Math.PI/180*degree;
		}
		
	}
}